import Vue from 'vue'
import VueRouter from 'vue-router'

import Main from "../views/Main.vue"
import welcome from "../views/main/welcome"
import fupin from '../views/main/fupin'
import yonghu from '../views/main/yonghu'
import shoucang from '../views/main/shoucang'
import pinkunhu from '../views/main/pinkunhu'
import zhiyuanzhe from '../views/main/zhiyuanzhe'
import liuyanban from '../views/main/liuyanban'
import lunbotu from '../views/main/lunbotu'

import Login from '../views/login/Login'

import Home from '../views/Home'
import pinkunView from '../views/home/pinkunView'
import liuyanView from '../views/home/liuyanView'
import fupinView from '../views/home/fupinView'
import userView from '../views/home/userView'
import zhiyuanzheView from '../views/home/zhiyuanzheView'
import pinkunInfo from '../views/home/pinkunInfo'
import fupinInfo from '../views/home/fupinInfo'
import zhiyuanzheInfo from '../views/home/zhiyuanzheInfo'
import zhiyuanzheshenqing from '../views/home/zhiyuanzheshenqing'

import Index from '../views/home/index'


Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/',
    name: 'home',
    component: Home,
    redirect: '/Index',
    children: [
      {
        path: '/index',
        component: Index
      },
      {
        path: '/pinkunView',
        component: pinkunView
      },
      {
        path: '/fupinView',
        component: fupinView
      },
      {
        path: '/liuyanView',
        component: liuyanView
      },
      {
        path: '/userView',
        component: userView
      },
      {
        path: '/zhiyuanzheView',
        component: zhiyuanzheView
      },
      {
        path: '/pinkunInfo/:id',
        component: pinkunInfo
      },
      {
        path: '/fupinInfo/:id',
        component: fupinInfo
      },
      {
        path: '/zhiyuanzheInfo/:id',
        component: zhiyuanzheInfo
      },
      {
        path: '/zhiyuanzheshenqing',
        component: zhiyuanzheshenqing
      },

    ]
  },
  {
    path: '/main',
    component: Main,
    children: [
      {
        path: '/welcome',
        component: welcome
      },
      {
        path: '/fupin',
        component: fupin
      },
      {
        path: '/yonghu',
        component: yonghu
      },
      {
        path: '/shoucang',
        component: shoucang
      },
      {
        path: '/pinkunhu',
        component: pinkunhu
      },
      {
        path: '/zhiyuanzhe',
        component: zhiyuanzhe
      },
      {
        path: '/liuyanban',
        component: liuyanban
      },
      {
        path: '/lunbotu',
        component: lunbotu
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // console.log(`触发路由守卫拦截${to.path}`);
  if (to.path == '/Index') return next()
  if (to.path == '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) {
    alert('您还没有登录，请先登录')
    return next('/login')
  }
  next()
})

export default router
